#include "stdafx.h"
#include "PairTrade.h"
#include "PairCalcLib.h"

CString PairTrade::GetDescription( ) const
{
	CString returnString;
	CString buyStock = BuyTrade->Stock.Name;
	CString sellStock = SellTrade->Stock.Name;
	if(Nature == 'B')
	{
		returnString.Format("Buy %d %s vs Sell %d %s ", BuyTrade->Qty, buyStock, SellTrade->Qty, sellStock);
	}
	else
	{
		returnString.Format("Sell %d %s vs Buy %d %s ", SellTrade->Qty, sellStock, BuyTrade->Qty, buyStock);
	}

	return returnString;
}

CString PairTrade::GetTradeSummary( ) const
{					
	// "Summary : (Sell 100 CVX on SDOT @ Bid) and (Buy 100 XOM on SDOT @ Bid)	
	CString returnString; 
	CString buyStock = BuyTrade->Stock.Name;
	CString sellStock = SellTrade->Stock.Name;

	CString buyOrderDestination = BuyTrade->OrderDestination;
	CString sellOrderDestination = SellTrade->OrderDestination;

	CString buyOrderPriceOn;
	if( !BuyTrade->OrderPriceOn.Compare( "B" ) ) buyOrderPriceOn = "Bid";
	if( !BuyTrade->OrderPriceOn.Compare( "A" ) ) buyOrderPriceOn = "Ask";
	if( !BuyTrade->OrderPriceOn.Compare( "L" ) ) buyOrderPriceOn = "Last";
	if( !BuyTrade->OrderPriceOn.Compare( "P" ) ) buyOrderPriceOn = "Mid Point";
	if( !BuyTrade->OrderPriceOn.Compare( "M" ) ) buyOrderPriceOn = "Market";

	CString sellOrderPriceOn;
	if( !SellTrade->OrderPriceOn.Compare( "B" ) ) sellOrderPriceOn = "Bid";
	if( !SellTrade->OrderPriceOn.Compare( "A" ) ) sellOrderPriceOn = "Ask";
	if( !SellTrade->OrderPriceOn.Compare( "L" ) ) sellOrderPriceOn = "Last";
	if( !SellTrade->OrderPriceOn.Compare( "P" ) ) sellOrderPriceOn = "Mid Point";
	if( !SellTrade->OrderPriceOn.Compare( "M" ) ) sellOrderPriceOn = "Market";

	returnString.Format("Summary : (Buy %d %s on %s @ %s) and (Sell %d %s on %s @ %s)", 
		BuyTrade->Qty, buyStock, buyOrderDestination, buyOrderPriceOn,
		SellTrade->Qty, sellStock, sellOrderDestination, sellOrderPriceOn);
	return returnString;
}

CString PairTrade::GetCellText(int col, bool title) const
{
	switch(col)
	{
		case 0: { static const CString title0(_T("Pair Name")); return title ? title0 : Description ; }
		case 1: { static const CString title1(_T("Description")); return title ? title1 : Description; }
		case 2: { static const CString title2(_T("Stock A")); return title ? title2 : (Nature == 'B'? BuyTrade->Stock.Name: SellTrade->Stock.Name);}
		case 3: { static const CString title3(_T("Price A")); return title ? title3 : (Nature == 'B'? ConvertToString(BuyTrade->Price) : ConvertToString(SellTrade->Price));}
		case 4: { static const CString title4(_T("Stock B")); return title ? title4 : (Nature == 'B'? SellTrade->Stock.Name: BuyTrade->Stock.Name);}
		case 5: { static const CString title5(_T("Price B")); return title ? title5 : (Nature == 'B'? ConvertToString(SellTrade->Price): ConvertToString(BuyTrade->Price));}
		case 6: { static const CString title6(_T("Acual Spread")); return title ? title6 : ConvertToString(ActualSpread);}
		case 7: { static const CString title7(_T("Status")); return title ? title7 : Status;}
		case 8: { static const CString title8(_T("Comparison")); return title ? title8 : Comparison;}
		case 9: { static const CString title9(_T("Required Spred")); return title ? title9 : ConvertToString(RequiredSpred);}
		case 10: { static const CString title10(_T("Evalution")); return title ? title10: (Evalution? "TRUE" : "FALSE");}
		case 11: { static const CString title11(_T("Realized Spread")); return title ? title11: ConvertToString(RealizedSpread);}
		case 12: { static const CString title12(_T("Pair Size")); return title ? title12 : PairSize;}

		default:{ static const CString emptyStr; return emptyStr; }
	}
}

int  PairTrade::GetColCount() const 
{ 
	return 13; 
}

PairTrade::PairTrade( const PairTrade& other )
{
	PairTradeID		= other.PairTradeID;
	ActualSpread	= other.ActualSpread;
	Status			= other.Status;
	Comparison		= other.Comparison;
	RequiredSpred	= other.RequiredSpred;
	Evalution		= other.Evalution;
	RealizedSpread	= other.RealizedSpread;
	PairSize		= other.PairSize;
	BuyTrade		= other.BuyTrade;
	SellTrade		= other.SellTrade;
	Nature			= other.Nature;
	Ratio			= other.Ratio;	
	IsActive		= other.IsActive;
	IsExecuted		= other.IsExecuted;
}

CString PairTrade::AssignPairTradeID()
{
	CString pairTradeID;
	SYSTEMTIME systime;
	GetSystemTime(&systime);
	pairTradeID.Format(_T("%.4d%.2d%.2d%.2d%.2d%.2d%.3d"), systime.wYear, systime.wMonth, systime.wDay, systime.wHour, systime.wMinute, systime.wSecond, systime.wMilliseconds);
	this->PairTradeID = pairTradeID;
	return pairTradeID;
}